package com.easytake.emotioncat.service.impl;

import com.easytake.emotioncat.component.MiniAppPropertiesBean;
import com.easytake.emotioncat.constant.UrlConstants;
import com.easytake.emotioncat.dto.MiniAppLoginRequest;
import com.easytake.emotioncat.dto.MiniAppLoginResponse;
import com.easytake.emotioncat.service.MiniAppService;
import com.easytake.emotioncat.util.HttpUtil;
import com.easytake.emotioncat.util.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MiniAppServiceImpl implements MiniAppService {

    @Autowired
    MiniAppPropertiesBean miniAppPropertiesBean;

    @Override
    public MiniAppLoginResponse authCode2Session(String code) {
        MiniAppLoginRequest requestData = new MiniAppLoginRequest();
        BeanUtils.copyProperties(miniAppPropertiesBean, requestData);
        requestData.setJs_code(code);
        return HttpUtil.get(UrlConstants.AUTH_CODE2SESSION_URL + StringUtil.getUrlParamString(requestData), MiniAppLoginResponse.class);
    }
}
